﻿using _8Group.MES.IAppService.Area;
using _8Group.MES.IAppService.Area.Dtos;
using _8Group.MES.IAppService.Location;
using _8Group.MES.IAppService.Location.Dtos;
using _8Group.MES.IAppService.ToolType;
using _8Group.MES.IAppService.ToolType.Dtos;
using _8Group.MES.IAppService.Warehouses;
using _8Group.MES.IAppService.Warehouses.Dtos;
using _8Group.MES.Model.WM仓储管理;
using FourGroups.Project;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;

namespace _8Group.MES.Web.Controllers
{
    /// <summary>
    /// 周扬控制器(个人任务的所有视图和方法都写在该控制器里)
    /// </summary>
    public class ZhouController : Controller
    {
        private readonly IWarehouseAppService _warehouseAppService;//仓库
        private readonly ILocationAppService _locationAppService;//库位
        private readonly IAreaAppService _areaAppService;//库区
        private readonly IToolTypeAppService _toolTypeAppService;//库区

        public ZhouController(IWarehouseAppService warehouseAppService, ILocationAppService locationAppService, IAreaAppService areaAppService, IToolTypeAppService toolTypeAppService)
        {
            _warehouseAppService = warehouseAppService;
            _locationAppService = locationAppService;
            _areaAppService = areaAppService;
            _toolTypeAppService = toolTypeAppService;
        }

        /// <summary>
        /// 工具类型设置
        /// </summary>
        /// <returns></returns>
        public IActionResult ToolTypeSetting()
        {
            return View();
        }

        /// <summary>
        /// 显示工具类型信息
        /// </summary>
        /// <returns></returns>
        public async Task<string> GetToolTypeList(string? toolTypeName, string? maintenType, int pageIndex = 1, int pageSize = 10)
        {
            var result = await _toolTypeAppService.GetToolTypes(toolTypeName, maintenType, pageIndex, pageSize);
            return result;
        }

        // <summary>
        /// 添加工具类型页面
        /// </summary>
        /// <returns></returns>
        public IActionResult AddToolTypeView()
        {
            return View();
        }

        /// <summary>
        /// 添加工具类型
        /// </summary>
        /// <param name="input">工具类型信息</param>
        /// <returns></returns>
        public async Task<int> AddToolType(CreateToolTypeDto input)
        {
            var result = await _toolTypeAppService.AddToolType(input);
            return result;
        }

        /// <summary>
        /// 删除工具类型
        /// </summary>
        /// <param name="id">工具类型Id</param>
        /// <returns></returns>
        public async Task<bool> DeleteToolType(int id)
        {
            var result = await _toolTypeAppService.DeleteToolType(id);
            return result;
        }

        // <summary>
        /// 更新工具类型页面
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdateToolTypeView()
        {
            return View();
        }

        /// <summary>
        /// 更新工具类型
        /// </summary>
        /// <param name="input">仓库信息</param>
        /// <returns></returns>
        public async Task<bool> UpdateToolType(UpdateToolTypeDto input)
        {
            var result = await _toolTypeAppService.UpdateToolType(input);
            return result;
        }

        /// <summary>
        /// 库位
        /// </summary>
        /// <returns></returns>
        public IActionResult StorageArea()
        {
            return View();
        }

        /// <summary>
        /// 显示库位信息
        /// </summary>
        /// <returns></returns>
        public async Task<string> GeAreaList(string? areaName, string? areaValue, int pageIndex = 1, int pageSize = 10)
        {
            var result = await _areaAppService.GetAreas(areaName, areaValue,pageIndex, pageSize);
            return result;
        }

        // <summary>
        /// 添加库位
        /// </summary>
        /// <returns></returns>
        public IActionResult AddAreaView()
        {
            return View();
        }

        /// <summary>
        /// 添加库位
        /// </summary>
        /// <param name="input">客户信息</param>
        /// <returns></returns>
        public async Task<int> AddArea(CreateAreaDto input)
        {
            var result = await _areaAppService.AddArea(input);
            return result;
        }

        /// <summary>
        /// 库区
        /// </summary>
        /// <returns></returns>
        public IActionResult StorageLocation()
        {
            return View();
        }

        /// <summary>
        /// 显示库区信息
        /// </summary>
        /// <returns></returns>
        public async Task<string> GeLocationList(string? locationName, int pageIndex = 1, int pageSize = 10)
        {
            var result = await _locationAppService.GeLocations(locationName, pageIndex, pageSize);
            return result;
        }

        // <summary>
        /// 添加库区
        /// </summary>
        /// <returns></returns>
        public IActionResult AddLocationView()
        {
            return View();
        }

        /// <summary>
        /// 添加库区
        /// </summary>
        /// <param name="input">客户信息</param>
        /// <returns></returns>
        public async Task<int> AddLocation(CreateLocationDto input)
        {
            var result = await _locationAppService.AddLocation(input);
            return result;
        }

        /// <summary>
        /// 仓库设置
        /// </summary>
        /// <returns></returns>
        public IActionResult WarehouseSetup()
        {
            return View();
        }

        /// <summary>
        /// 显示仓库信息
        /// </summary>
        /// <returns></returns>
        public async Task<string> GetWarehouseList(string? warehouseCode, string? warehouseName, int pageIndex = 1, int pageSize = 10)
        {
            var result = await _warehouseAppService.GetWarehouses(warehouseCode, warehouseName, pageIndex, pageSize);
            return result;
        }

        // <summary>
        /// 添加仓库
        /// </summary>
        /// <returns></returns>
        public IActionResult AddWarehouseView()
        {
            return View();
        }

        /// <summary>
        /// 添加仓库
        /// </summary>
        /// <param name="input">客户信息</param>
        /// <returns></returns>
        public async Task<int> AddWarehouse(CreateWarehouseDto input)
        {
            var result = await _warehouseAppService.AddWarehouse(input);
            return result;
        }

        /// <summary>
        /// 删除仓库
        /// </summary>
        /// <param name="id">仓库编号</param>
        /// <returns></returns>
        public async Task<bool> DeleteWarehouse(int id)
        {
            var result = await _warehouseAppService.DeleteWarehouse(id);
            return result;
        }

        // <summary>
        /// 更新仓库    
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdateWarehouseView()
        {
            return View();
        }

        /// <summary>
        /// 修改仓库
        /// </summary>
        /// <param name="input">仓库信息</param>
        /// <returns></returns>
        public async Task<bool> UpdateWarehouse(UpdateWarehouseDto input)
        {
            var result = await _warehouseAppService.UpdateWarehouse(input);
            return result;
        }
    }
}
